<template>
	<view>
		<xupload :show-progress="true" :upload-text="uploadText" multiple ref="uUpload" :header="header"
			:action="action" :auto-upload="true" :max-size="5* 1024 * 1024" @on-change="onChoose"
			:max-count="maxCount" :fileList="fileList" @on-list-change="onListChange" @on-uploaded="onUploaded"
			@on-progress="onProgress" @on-remove="remove" @befordelIndex="befordelIndex">
		</xupload>
	</view>
</template>

<script>
	import config from '@/libs/config.js'
	export default {
		props:{
			maxCount: {
				type: [String, Number],
				default: 9
			},
		},
		data() {
			return {
				action: config.ossUrl,
				header: {
					'Authorization': uni.getStorageSync('openid') ? uni.getStorageSync(
						'openid') : ''
				},
				FormData: [],
				uploadText: '上传图片,不超过5M',
				fileList: [],
				delIndex: '',
			}
		},
		onLoad() {},
		methods: {
			onChoose() {
				//获取图片路径
				let imgpat = this.$refs.uUpload.lists;
				this.FormData = imgpat
				this.toNext()
			},
			toNext() {
				let data = this.FormData.filter(i => {
					return i.response && i.response.code != 0
				})
				if (data.length > 0) {
					this.$refs.uUpload.clear()
					uni.showToast({
						title: '未登录',
						icon: "none"
					})
					setTimeout(() => {
						let path = 'pages/componentsIndex/login'
						uni.$u.route({
							url: path,
						})
					}, 1000)
				} else {
					// console.log('上传完成');
					// this.$emit('change', this.FormData)
				}
			},
			onListChange(list, name) {
				this.$emit('change', list)
			},
			onUploaded(list, name) {
				this.$emit('changeSuccess', list)
			},
			remove(index, lists) {
				this.$emit('removeImg', this.delIndex)
			},
			befordelIndex(index) {
				this.delIndex = index
			},
			onProgress(res, index, lists, name) {
				this.fileList = lists
			}
		}
	}
</script>

<style scoped lang="scss">
</style>